#include <bits/stdc++.h>
using namespace std;

int read() {
    int x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-') f *= -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * f;
}

void print(int x) {
    if (x < 0) {
        putchar('-');
        x *= -1;
    }
    if (x > 9) print(x / 10);
    putchar(x % 10 + '0');
}
void el() {
    puts("");
}
const int N = 100005;
int d[N], p[N];
double v[N], a[N];

int main() {
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    int T = read();
    while (T--) {
        int n = read(), m = read(), L = read(), V = read(), ans = 0, minn = INT_MAX;
        for (int i = 1; i <= n; i++) {
            d[i] = read(), v[i] = read(), a[i] = read();
            minn = min(minn, d[i]);
        }
        for (int i = 1; i <= m; i++)
                p[i] = read();
        for (int i = 1; i <= n; i++) {
            if (v[i] > V && d[i] <= p[m]) ans++;
        }
        print(ans);
        putchar(' ');
        if (minn > p[m]) print(m);
        else print(m - 1);
        el();
    }
    return 0;
}
